<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>


    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	<title>Bootstrap 101 Template</title>

	<!-- Bootstrap -->
	<link href="__CSS__/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" href="__CSS__/my.css">
	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
	<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
	<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<script src="__JS__/jquery.min.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="__JS__/bootstrap.min.js"></script>
	
</head>
<body>

  <div class="container">
      	 <div class="col-md-12 bg-primary p10">
      	 	<h6>用户列表</h6>
            <button class="btn btn-default" data-toggle="modal" data-target="#myModal">
             用户添加
            </button>
      	 </div>



           <!-- 模态框（Modal） -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                      &times;
                    </button>

                      <div class="alert alert-success" role="alert">
                        <h4 class="modal-title  bg-success" id="myModalLabel">
                    用户添加
                        </h4>
                      </div>
                   </div>

                 <form class="form-horizontal" action="{:url('admin/Users/add')}" method='post' enctype="multipart/form-data" name="form1">

                            <div class="modal-body">

                                <table class="table table-bordered" style="color:black">
                                    <tr>
                                        <td>用户电话</td>
                                        <td><input type="text" name='phone'></td>
                                    </tr>
                                    <tr>
                                        <td>用户密码</td>
                                        <td><input type="password"  name='password' value=""></td>
                                    </tr>
                                    <tr>
                                      <td>用户名字</td>
                                      <td><input type="text" name="name"></td>
                                    </tr>

                                
                                    <tr>
                                        <td>性别</td>
                                        <td>
                                            <input type="radio" name='sex' value='0'> 男
                                            <input type="radio" name='sex' value='1'> 女
                                   
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>生日</td>
                                        <td><input type="text" name="birthday"></td>
                                    </tr>

                              

                                    <tr>
                                        <td>地址</td>
                                        <td><input type="text" name="address"></td>
                                    </tr>



                                    <tr>
                                      
                                        <td>图片</td>
                                        <td>  <input type="file" class="file" name="image" >
                                                </td>
                                    </tr>


                                       <tr>
                                        <td>详情</td>
                                        <td>
                                            <textarea name="dex" id="" cols="30" rows="10" ></textarea>
                                        </td>
                                    </tr>
                                 
                                </table>



                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                </button>
                                <button class="btn btn-primary " type='submit' >
                                    保存
                                </button>
                            </div>
                        </form>

                </div><!-- /.modal-content -->
              </div><!-- /.modal -->
            </div>



















      	   	 <div class="col-md-12">
      	 	<table class="table table-hover bg-info">
      	 		<tr>
      	 			<th>ID</th>
      	 			<th>电话</th>
      	 			<th>密码</th>
      	 			<th>名字</th>
      	 			<th>性别</th>
      	 			<th>详情</th>
      	 			<th>生日</th>
      	 			<th>注册时间</th>
      	 			<th>地址</th>
      	 			<th>头像</th>
      	 			<th>状态</th>
              <th>操作</th>
      	 		</tr>
      	 		
      	 		{foreach $list as $v}
                <tr>
                	<td>{$v['id']}</td>
                    <td>{$v['phone']}</td>
                    <td>{$v['password']}</td>
                    {if empty($v['name'])}
                    <td>{$v['phone']}</td>
                    {else}
                    <td>{$v['name']}</td>
                    {/if}
                   <td>{if $v['sex']==0 }
                      男
                      {else} 
                      女
                  
                     
	                {/if}
	                </td>
                    <td>{$v['introduce']}</td>
                    <td>{$v['birthday']}</td>
                    <td>{$v['createtime']}</td>
                    <td>{$v['address']}</td>
                    {if empty($v['icon'])}
                    <td><img src="__IMG__/1.jpg" style="width:80px;height:80px"></td>
                    {else}
                    <td><img src="__UPLOAD__{$v.icon}" style="width:80px;height:80px"></td>
                    {/if}

                    <td>
	                    {if $v['status']==1}                                      
		                    <button data-id="{$v['id']}" class="btn btn-danger btn-xs lahei">
		                        正常
		                    </button>
	                    {else}
							<button data-id="{$v['id']}" class="btn btn-danger btn-xs lahei" style="background-color:black">
							    拉黑
							</button>
	                    {/if}
                    </td>

                    <td class="col-md-2">
                        <a href="{:url('admin/Users/edit',['id'=>$v['id']])}" class="btn btn-primary btn-xs">编辑</a>
                        <button data-id="{$v['id']}" class="btn btn-danger btn-xs del-btn" >删除</button>
                    </td>
                 
                </tr>

      	 		{/foreach}
      	 	</table>
      	 </div>
  </div>




  <script>
  	   	$(function(){
            //触发用户权限修改
            $('.lahei').click(function(){
             var ac_id = $(this).attr('data-id');
            // if (confirm('您确定?')) {
            	var obj = $(this);
            	delAjax(ac_id,obj);//执行拉黑操作
           	 	// }         
            })
      	});

      	function delAjax(id,obj)
      	{
      	  $.ajax({
      	  	type:'get',
      	  	url:'/admin/Users/change/id/' + id,
      	  	dateType:'json',

      	  	success:function(data){
      	  	
              if (data==1) {
                 alert('操作成功!!!');
               	 location = location;
              }else{
                 alert('操作失败!!!');
                 
              }
      	  	},
      	  	error:function(){
      	  		//Ajax执行失败
      	  		alert('Ajax执行失败');
      	  		// location = location;
      	  	}

      	  });
      	}





        $(function(){
            //触发用户删除
            $('.del-btn').click(function(){
             var ac_id = $(this).attr('data-id');
            if (confirm('您确定要[删除]该用户么?')) {

              var obj = $(this).parents('tr');
              delAjax(ac_id,obj);//执行删除操作
            }

            

            })



            

        });

        function delAjax(id,obj)
        {
          $.ajax({
            type:'delete',
            url:'/admin/Users/delete/id/' + id,
            // dateType:'json',

            success:function(data){
              if (data.status) {
                 alert('删除成功!!!');
                 obj.remove();
              }else{
                 alert('删除失败!!!');
              }
            },

            error:function(){
              //Ajax执行失败
              alert('Ajax执行失败')
            }

          });
        }

   
  
  </script>
	
</body>
</html>